From 89ba0e3b1b96f5ae8fa12c313b448a5f104e0557 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 16 Sep 2004 04:43:15 +0000 Subject: [PATCH] Add rest of shims to hook up Garmin/USB layers. --- gpsbabel/jeeps/garminusb.h | 2 +- gpsbabel/jeeps/gpsread.c | 38 ++++++++------------------------------ gpsbabel/jeeps/gpssend.c | 14 +++++++++++++- gpsbabel/jeeps/gpsserial.c | 22 +++++++++++++++++++--- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/gpsbabel/jeeps/garminusb.h b/gpsbabel/jeeps/garminusb.h index 2a063a95f..eb448b67f 100644 --- a/gpsbabel/jeeps/garminusb.h +++ b/gpsbabel/jeeps/garminusb.h @@ -38,7 +38,7 @@ union { unsigned char datasz[4]; unsigned char databuf[1]; /* actually an variable length array... */ } gusb_pkt; - unsigned char dbuf[MAX_GPS_PACKET_SIZE]; + unsigned char dbuf[1024]; } garmin_usb_packet; /* diff --git a/gpsbabel/jeeps/gpsread.c b/gpsbabel/jeeps/gpsread.c index 6f9004eb3..d37fe6f3e 100644 --- a/gpsbabel/jeeps/gpsread.c +++ b/gpsbabel/jeeps/gpsread.c @@ -82,6 +82,10 @@ int32 GPS_Packet_Read(int32 fd, GPS_PPacket *packet) len = 0; isDLE = gpsFalse; p = (*packet)->data; + + if (gps_is_usb) { + return GPS_Packet_Read_usb(fd, packet); + } start = GPS_Time_Now(); GPS_Diag("Rx Data:"); @@ -191,6 +195,10 @@ int32 GPS_Packet_Read(int32 fd, GPS_PPacket *packet) int32 GPS_Get_Ack(int32 fd, GPS_PPacket *tra, GPS_PPacket *rec) { + if (gps_is_usb) { + return 1; + } + if(!GPS_Packet_Read(fd, rec)) return 0; @@ -208,33 +216,3 @@ int32 GPS_Get_Ack(int32 fd, GPS_PPacket *tra, GPS_PPacket *rec) return 1; } - - - - - -#if 0 - -int32 ajb(int32 fd) -{ - UC u; - int32 n; - - while(1) - { - if((n=GPS_Serial_Chars_Ready(fd))) - { - if(read(fd,&u,1)==-1) - { - perror("read"); - GPS_Error("NMEA Read: Read error"); - gps_errno = FRAMING_ERROR; - return 0; - } - printf("%d %c\n",u,u); - } - } - - return 0; -} -#endif diff --git a/gpsbabel/jeeps/gpssend.c b/gpsbabel/jeeps/gpssend.c index fce480cb2..c4b299d7a 100644 --- a/gpsbabel/jeeps/gpssend.c +++ b/gpsbabel/jeeps/gpssend.c @@ -45,9 +45,15 @@ void GPS_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n) int32 i; UC chk=0; + p = data; q = (*packet)->data; + + if (gps_is_usb) { + GPS_Make_Packet_usb(packet, type, data, n); + return; + } (*packet)->dle = DLE; (*packet)->edle = DLE; @@ -55,7 +61,7 @@ void GPS_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n) (*packet)->n = n; (*packet)->type = type; (*packet)->bytes = 0; - + chk -= type; if(n == DLE) @@ -126,6 +132,9 @@ int32 GPS_Write_Packet(int32 fd, GPS_PPacket packet) size_t ret; const char *m1, *m2; + if (gps_is_usb) + return GPS_Write_Packet_usb(fd, packet); + GPS_Diag("Tx Data:"); Diag(&packet->dle, 3); if((ret=GPS_Serial_Write(fd,(const void *) &packet->dle,(size_t)3)) == -1) @@ -193,6 +202,9 @@ int32 GPS_Write_Packet(int32 fd, GPS_PPacket packet) int32 GPS_Send_Ack(int32 fd, GPS_PPacket *tra, GPS_PPacket *rec) { UC data[2]; + + if (gps_is_usb) + return 1; GPS_Util_Put_Short(data,(US)(*rec)->type); GPS_Make_Packet(tra,LINK_ID[0].Pid_Ack_Byte,data,2); diff --git a/gpsbabel/jeeps/gpsserial.c b/gpsbabel/jeeps/gpsserial.c index b552ecf01..31345fe3a 100644 --- a/gpsbabel/jeeps/gpsserial.c +++ b/gpsbabel/jeeps/gpsserial.c @@ -83,6 +83,14 @@ int32 GPS_Serial_On(const char *port, int32 *fd) DCB tio; COMMTIMEOUTS timeout; + if (gps_is_usb) { + switch (gusb_open(port)) { + case 0: return NULL; + case 1: return 1; + case 2: exit(0); + } + } + comport = CreateFile(port, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); @@ -143,7 +151,11 @@ int32 GPS_Serial_On(const char *port, int32 *fd) int32 GPS_Serial_Off(const char *port, int32 fd) { - CloseHandle(comport); + if (gps_is_usb) { + gusb_close(port); + } else { + CloseHandle(comport); + } return 1; } @@ -356,7 +368,7 @@ int32 GPS_Serial_Read(int32 handle, void *ibuf, int size) int32 GPS_Serial_Write(int32 handle, const void *obuf, int size) { - return write(handle, obuf, size); + return write(handle, obuf, size); } @@ -460,6 +472,8 @@ int32 GPS_Serial_Wait(int32 fd) fd_set rec; struct timeval t; + if (gps_is_usb) return 1; + FD_ZERO(&rec); FD_SET(fd,&rec); @@ -487,7 +501,9 @@ int32 GPS_Serial_Wait(int32 fd) int32 GPS_Serial_On(const char *port, int32 *fd) { - + if (gps_is_usb) { + return gusb_init(); + } if(!GPS_Serial_Savetty(port)) { GPS_Error("Cannot access serial port"); -- 2.30.2